﻿using Comm100.Framework.Domain.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using Bot.Domain.Bo;
using Castle.Windsor;
using Bot.Domain.Specifications;

namespace Bot.Domain.Categories.Service
{
    public class NoAnswerMessageInChannelDomainService : INoAnswerMessageInChannelDomainService
    {
        private IWindsorContainer _container;
        private readonly IRepository<Guid, NoAnswerMessageInChannel> _repository;

        public NoAnswerMessageInChannelDomainService(IRepository<Guid, NoAnswerMessageInChannel> repository, IWindsorContainer container)
        {
            this._repository = repository;
            this._container = container;
        }

        public NoAnswerMessageInChannel Create(NoAnswerMessageInChannel noAnswerMessageInChannel)
        {
            if (noAnswerMessageInChannel.Id == Guid.Empty)
            {
                noAnswerMessageInChannel.Id = Guid.NewGuid();
            }
            return _repository.Create(noAnswerMessageInChannel);
        }

        public NoAnswerMessageInChannel Get(Guid id)
        {
            return _repository.Get(id);
        }

        public NoAnswerMessageInChannel Update(NoAnswerMessageInChannelUpdateBo bo)
        {
            NoAnswerMessageInChannel noAnswerMessageInChannel = _repository.Get(bo.Id);
            //noAnswerMessageInChannel.Id = bo.Id;
            //noAnswerMessageInChannel.BotId = bo.BotId;
            noAnswerMessageInChannel.Channel = bo.Channel;
            noAnswerMessageInChannel.Message = bo.Message;
            noAnswerMessageInChannel.IfIncludeContactAgentOption = bo.IfIncludeContactAgentOption;

            _repository.Update(noAnswerMessageInChannel);

            return noAnswerMessageInChannel;

        }

        public IEnumerable<NoAnswerMessageInChannel> List()
        {
            return _repository.ListAll();
        }

        public void Delete(Guid id)
        {
            NoAnswerMessageInChannel noAnswerMessageInChannel = _repository.Get(id);

            _repository.Delete(noAnswerMessageInChannel);

        }

        public IEnumerable<NoAnswerMessageInChannel> GetByBotId(Guid botId)
        {
            var noAnswerMessageInChannels = _repository.List(new NoAnswerMessageInChannelFilterSpecification(botId));
            return noAnswerMessageInChannels;
        }
    }
}
